using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Omniture.API;
using WeifenLuo.WinFormsUI.Docking;

namespace Omniture.Studio
{
	public partial class ObjectsWindow : DockContent
	{
		private OmnitureProject _project = null;
		private bool _allowDisplay = false;

		public ObjectsWindow()
		{
			InitializeComponent();

			lstEvar.MouseDown += new MouseEventHandler(ListBox_MouseDown);
			lstEvent.MouseDown += new MouseEventHandler(ListBox_MouseDown);
			lstProp.MouseDown += new MouseEventHandler(ListBox_MouseDown);

			this.AddTooTip(lstEvar, "Evar List", "The is a list of all 'Evar' objects in this project. To associate an object from this window to a web page, drag it to the 'Evar' list of the page.");
			this.AddTooTip(lstProp, "Prop List", "The is a list of all 'Prop' objects in this project. To associate an object from this window to a web page, drag it to the 'Prop' list of the page.");
			this.AddTooTip(lstEvent, "Event List", "The is a list of all 'Event' objects in this project. To associate an object from this window to a web page, drag it to the 'Event' list of the page.");

		}

		public bool AllowDisplay
		{
			get { return _allowDisplay; }
			set { _allowDisplay = value; }
		}

		public OmnitureProject Project
		{
			get { return _project; }
			set
			{
				_project = value;
				UpdateDisplay();
			}
		}

		public void UpdateDisplay()
		{
			lstEvar.Items.Clear();
			lstEvent.Items.Clear();
			lstProp.Items.Clear();
			if (!this.AllowDisplay) return;

			if (_project != null)
			{
				lstEvar.Items.AddRange(this.Project.EVarList.ToArray());
				lstEvent.Items.AddRange(this.Project.EventList.ToArray());
				lstProp.Items.AddRange(this.Project.PropList.ToArray());
			}
		}

		private void AddTooTip(Control ctrl, string header, string text)
		{
			helpProvider1.SetHelpString(ctrl, header + "\n\n" + text);
			toolTip1.SetToolTip(ctrl, header + "\n\n" + text);
		}

		private void ListBox_MouseDown(object sender, MouseEventArgs e)
		{
			ListBox lb = (ListBox)sender;
			if (lb.SelectedIndex != -1)
			{
				lb.DoDragDrop(lb.Items[lb.SelectedIndex], DragDropEffects.Copy);
			}
		}

	}
}